package com.you.base.jdkproxy;

import java.lang.reflect.Proxy;

public class TestProxy {

    public static void main(String[] args) {
        User user = new User();
        user.setName("you");
        //调用真正的实现类
        IUserService userService = new UserServiceImpl();
        userService.showUserInfo(user);
        //调用代理实现类
        UserServiceProxy userServiceProxy = new UserServiceProxy(userService);
        IUserService proxy = (IUserService) Proxy.newProxyInstance(userService.getClass().getClassLoader(),
                UserServiceImpl.class.getInterfaces(), userServiceProxy);
        proxy.showUserInfo(user);
    }
}
